<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin: 0px;
            padding: 0px;
            list-style: none;
        }
        table{
            border-collapse: collapse;
            margin: 10px auto;
        }
        td{
            border: 1px solid #cccccc;
            width: 150px;
            line-height: 40px;
            text-align: center;
            
        }
        .head{
            font-weight: bold;
            color: white;
            font-size: 20px;
            background-color: orange;
        }
        input{
            text-align: center;
        }
        input:nth-of-type(1){
            display: block;
            margin: auto;
        }
        input:nth-of-type(2){
            display: block;
            margin: auto;
        }
        button{
            display: block;
            margin:auto;
            width: 200px;
            line-height: 40px;
            background: orange;
            outline: none;
            border: none;
            cursor: pointer;
        }
        .del{
            cursor: pointer;
        }
        .edit{
            cursor: pointer;
        }
    </style>
</head>
    <body>
        <input type="text" placeholder="请输入商品名称" id="product"><br>
        <input type="text" placeholder="请输入商品价格" id="price"><br>
        <button id="btn">增加</button>
        <table id="box">
            <tr class="head">
                <td>商品名称</td>
                <td>价格</td>
                <td>数量</td>
                <td>编辑</td>
                <td>删除</td>
            </tr>
            <tr>
                <td><input type="text" value="华为" disabled></td>
                <td><input type="text" value="5999" disabled></td>
                <td>500</td>
                <td onclick="edit(this)" class="edit">编辑</td>
                <td onclick="del(this)" class="del">删除</td>
            </tr>
        </table>


        <script>
            var button = document.getElementById('btn');
            var product = document.getElementById('product');
            var price = document.getElementById('price');
            btn.onclick=function(){
                var pro = product.value;
                var pri = price.value;
                var tag = document.createElement('tr');
                tag.innerHTML=`<td><input type="text" value="${pro}" disabled></td>
                <td><input type="text" value="${pri}" disabled></td>
                <td>500</td>
                <td onclick="edit(this)" class="edit">编辑</td>
                <td onclick="del(this)" class="del">删除</td>`
                box.appendChild(tag);
            }

            function del(a){
                a.parentNode.parentNode.removeChild(a.parentNode);
            }
            function edit(a){
                if(a.innerHTML=="编辑"){
                    a.innerHTML='确认';
                    a.parentNode.children[0].children[0].removeAttribute('disabled');
                    a.parentNode.children[1].children[0].removeAttribute('disabled');
                }else{
                    a.innerHTML='编辑';
                    a.parentNode.children[0].children[0].disabled='true';
                    a.parentNode.children[1].children[0].disabled='true';
                }
            }
        </script>
    </body>
</html>